# -*- coding: utf-8 -*-
import random
# 先导入后续要使用的包
import time, pyautogui
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait

# 创建一个webDriver的实例，接下来的所有操作都是在该实例上进行，以Chrome实例为例
driver = webdriver.Chrome()
# 窗口最大化
driver.maximize_window()
# 访问德科数智系统
driver.get("http://172.16.91.154//login")
driver.implicitly_wait(3)
# 通过元素id找到对应元素并输入值进行搜索；此处为在百度搜索框输入selenium并点击查询
driver.find_element(By.XPATH, "//input[@placeholder='账号名称']").send_keys("20280")
driver.find_element(By.XPATH, "//input[@placeholder='密码']").send_keys("000000")
driver.find_element(By.XPATH, "//span[text()='登录']").click()
time.sleep(5)
driver.find_element(By.XPATH, "//span[text()='客户关系管理']").click()
driver.find_element(By.XPATH,"//span[text()='商机列表']").click()
driver.find_element(By.XPATH,"//span[text()=' 新增']").click()
driver.find_element(By.XPATH,"//div[@aria-label='新增商机']/section/div/div/div/div/form/div[1]/div/div/div[2]/div/div/div").click()
time.sleep(2)
driver.find_element(By.XPATH,"//span[text()='华为商城']").click()
current_timestamp = int(time.time())
# driver.find_element(By.XPATH,"//div[@aria-label='新增商机']/section/div/div/div[1]/div/form/div[1]/div[2]/div/div[2]/div/div/input").click()
driver.find_element(By.XPATH,"//div[@aria-label='新增商机']/section/div/div/div[1]/div/form/div[1]/div[2]/div/div[2]/div/div/input").send_keys('这是商机'+str(current_timestamp))

driver.find_element(By.XPATH,"//div[contains(@class,'addOrEditOpportunity')]/div/div/div/form/div/div[3]/div/div[2]/div/div").click()
time.sleep(2)
driver.find_element(By.XPATH,"//span[text()='新商机']").click()

driver.find_element(By.XPATH,"//div[@aria-label='新增商机']/section/div/div[1]/div/div/form/div/div[4]/div/div[2]/div/div/textarea").send_keys('这是商机描述')

driver.find_element(By.XPATH,"//div[@aria-label='新增商机']/section/div/div[1]/div/div/form/div/div[5]/div/div[2]/div/div/div/input").click()
time.sleep(2)
driver.find_element(By.XPATH,"//span[text()='意向沟通']").click()

driver.find_element(By.XPATH,"//input[@max='99999999999']").send_keys('456512')

driver.find_element(By.XPATH,"//div[@aria-label='新增商机']/section/div/div[1]/div/div/form/div/div[7]/div/div[2]/div/div/div[2]/input").click()
time.sleep(2)
driver.find_element(By.XPATH,"//div[contains(@id,'cascader-menu')]/div/ul/li[3]/label/span/span").click()
driver.find_element(By.XPATH,"//span[text()='新增商机']").click()

driver.find_element(By.XPATH,"//div[@aria-label='新增商机']/section/div/div[1]/div/div/form/div/div[8]/div/div[2]/div/div/input").click()
time.sleep(2)
driver.find_element(By.XPATH,"//td[@class='available']/div/span[contains(text(),'18')]").click()
# WebDriverWait(driver,5,2).until(lambda driver:driver.find_element(By.XPATH,"//td[@class='available']/div/span[contains(text(),'18')]")).click()

driver.find_element(By.XPATH,"//span[text()='提交']").click()


# from selenium.webdriver.common.by import By
# from selenium.webdriver.support.ui import WebDriverWait
# from selenium.webdriver.support import expected_conditions as EC
#
# try:
#     element = WebDriverWait(driver, 10).until(
#         EC.presence_of_element_located((By.CSS_SELECTOR,'#card > div > div.vxe-grid.is--animat.is--round > div > div.vxe-table--render-wrapper > div.vxe-table--fixed-wrapper > div.vxe-table--fixed-right-wrapper.scrolling--middle > div.vxe-table--body-wrapper.fixed-right--wrapper > table > tbody > tr:nth-child(1) > td.vxe-body--column.col_39.col--left.col--last.col--ellipsis > div > div > div:nth-child(1) > div > span'))
#     )
#     element.click()
# except Exception:
#     print("在指定时间内元素未出现")

# time.sleep(2)
# driver.find_element(By.XPATH,'//*[@id="card"]/div/div[1]/div/div[2]/div[2]/div[2]/div[2]/table/tbody/tr[1]/td[9]/div/div/div[1]/div/span').click()

# driver.find_element(By.XPATH,"//input[@max='99999999999']").clear()
# time.sleep(1)
# driver.find_element(By.XPATH,"//input[@max='99999999999']").send_keys('4545454')








